<template>
  <div>
    <!-- 发票邮寄查询 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        columnsRef="qjhInvoiceMailQuery"
        :isSelectColumn="false"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :onColumnsChange="columns => (this.columns = columns)"
      >
        <template slot="controls" slot-scope="props">
          <multiuse-button size="small" type="primary" :click="exportHandle">导 出</multiuse-button>
        </template>
      </FilterTable>
    </Spin>

    <BaseDialog :visible.sync="visible" title="物流信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SonModel :rowData="formData" @close="emitCloseHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils/index';
import { queryList, exportExcel,exporturl } from '@/api/dealerFinance/InvoiceManage/InvoiceMailQuery';
import SonModel from './SonModel';

export default {
  name: 'InvoiceMailQuery',
  mixins: [dictionary],
  components: {
    SonModel
  },
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {},
      formData: {},
      visible: false,
      exportLoading: false
    };
  },
  created() {},
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    detailHandle(row) {
      this.visible = true;
      this.formData = row;
    },
    emitCloseHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    // 导出
    async exportHandle() {
        let json = Object.assign({}, { CODE: 'CODE_00000238' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // await this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
      //   confirmButtonText: '下载',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // })
      //   .then(() => {
      //     this.exportLoading = true;

      //     exportExcel(this.fetchParams)
      //       .then(response => {
      //         exportExcelFile(response.data, '发票邮寄查询');
      //         this.exportLoading = false;
      //       })
      //       .catch(err => {
      //         console.log(err);
      //       });
      //   })
      //   .catch(() => {
      //     this.$message({
      //       type: 'info',
      //       message: '已取消'
      //     });
      //   });
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '快递单号',
          fieldName: 'courierNo',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '邮寄状态',
          fieldName: 'postType',
          placeholder: '请选择',
          itemList: this.createDictList('6090')
        },
        {
          type: 'RANGE_DATE',
          label: '快递日期',
          dateType: 'exactdaterange',
          fieldName: 'courierStrartDate|courierEndDate',
          dateType: 'exactdaterange'
        },
        {
          type: 'INPUT',
          label: '发票号码',
          fieldName: 'goldenInvoiceNo',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '快递公司',
          fieldName: 'courierCompany',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '动力形式',
          fieldName: 'powerType',
          placeholder: '请选择',
          itemList: this.createDictList('6008')
        },
        {
          type: 'SELECT',
          label: '业务类型',
          fieldName: 'buzinessType',
          placeholder: '请选择',
          itemList: this.createDictList('6089')
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '邮寄单号',
          dataIndex: 'mailNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '动力形式',
          dataIndex: 'powerType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6008'),
          render: props => {
            return <span>{this.createDictText(props.row.powerType, '6008')}</span>;
          }
        },
        {
          title: '业务类型',
          dataIndex: 'buzinessType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6089'),
          render: props => {
            return <span>{this.createDictText(props.row.buzinessType, '6089')}</span>;
          }
        },
        {
          title: '开票日期',
          dataIndex: 'invoiceDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '发票号码',
          dataIndex: 'goldenInvoiceNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发票代码',
          dataIndex: 'goldenInvoiceCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '邮寄状态',
          dataIndex: 'postType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6090'),
          render: props => {
            return <span>{this.createDictText(props.row.postType, '6090')}</span>;
          }
        },
        {
          title: '店端签收状态',
          dataIndex: 'receiptStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6091'),
          render: props => {
            return <span>{this.createDictText(props.row.receiptStatus, '6091')}</span>;
          }
        },
        {
          title: '异常原因',
          dataIndex: 'abnormalReason',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '快递公司',
          dataIndex: 'courierCompany',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '快递单号',
          dataIndex: 'courierNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            if (props.row.courierNo) {
              return (
                <el-link type="primary" underline={false} onClick={() => this.detailHandle(props.row)}>
                  {props.row.courierNo}
                </el-link>
              );
            }
          }
        },
        {
          title: '快递日期',
          dataIndex: 'courierDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '店端签收日期',
          dataIndex: 'receiptDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '退回快递公司',
          dataIndex: 'backCourierCompany',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '退回快递单号',
          dataIndex: 'backCourierNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '退回快递日期',
          dataIndex: 'backCourierDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '厂端签收日期',
          dataIndex: 'backReceiptDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
<style scoped>
.el-link {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  position: relative;
  text-decoration: none;
  outline: none;
  cursor: pointer;
  padding: 0;
  font-size: 12px;
  font-weight: 500;
}
</style>
